package com.lm.activiti.boot.tools;

import com.google.common.collect.Lists;
import com.lm.activiti.boot.annotation.ex.DataException;
import org.joda.time.DateTime;
import org.joda.time.Duration;
import org.joda.time.Interval;
import org.junit.Test;

import java.util.Date;
import java.util.List;
import java.util.Objects;

/**
 * @author lm_jcf
 * @date 2020/1/17 14:50
 */
public class JodaTimeTest {

    public static void main(String[] args) {
        DateTime end = new DateTime();
        DateTime start = new DateTime(2020,1,18,0,0,0);

        Duration d = new Duration(start, end);
//        System.out.println(d.getStandardSeconds());

        System.out.println(withinInterval(
                new DateTime(2021, 7, 8, 12, 1, 1).toDate(),
                new DateTime(2021, 7, 8, 13, 1, 1).toDate(),
                new DateTime(2021, 7, 8, 12, 0, 1).toDate()
        ));
    }

    @Test
    public void hutoolDateTime(){

        cn.hutool.core.date.DateTime dateTime = new cn.hutool.core.date.DateTime();

        System.out.println(dateTime.dayOfWeekEnum().toChinese());

        DateTime jodaDateTime = new DateTime();
        System.out.println(jodaDateTime.dayOfWeek().getAsText());


        List<String> list = Lists.newArrayList("1", "2");
        System.out.println(list.contains(String.valueOf(1)));

    }

    public static boolean withinInterval(Date start, Date end, Date checkDate) {
        if (Objects.isNull(start) || Objects.isNull(end) || Objects.isNull(checkDate)) {
            throw new DataException("判断是否在时间段内错误，参数不能为空","10002");
        }

        Interval interval = new Interval(start.getTime(), end.getTime());
        return interval.contains(checkDate.getTime());
    }

}
